using System.Drawing;
using FireStarterModeller.BO;
using Habanero.BO;
using Habanero.Faces.Base;
using Habanero.Faces.Win;

namespace FireStarterModeller.UI
{
    /// <summary>
    /// - The <see cref="BOGridAndEditorControlWin"/> for <see cref="DMRelationship"/>
    /// -  and the <see cref="DMRelatedPropertiesControl"/> used to edit the Relationship Properties.
    /// </summary>
    public class DMRelationshipsControl : PanelWin, IFormControl
    {
        private DMClass _dmClass;
        private readonly DMRelationshipSelectorControl _relationshipSelector;
        private readonly DMRelationshipEditorControl _relationshipEditorControl;

        public DMRelationshipsControl(IControlFactory controlFactory)
        {
            _relationshipSelector = new DMRelationshipSelectorControl(controlFactory) {Width = 400};
            _relationshipEditorControl = new DMRelationshipEditorControl(controlFactory);

            BorderLayoutManager layoutManager = controlFactory.CreateBorderLayoutManager(this);
            layoutManager.AddControl(RelationshipSelector, BorderLayoutManager.Position.West, true);
            layoutManager.AddControl(RelationshipEditorControl, BorderLayoutManager.Position.Centre);
            new BOSelectorAndEditorManager(_relationshipSelector, _relationshipEditorControl);
            UpdateState();
            this.Height = RelationshipEditorControl.MinimumSize.Height;
            //this.MaximumSize = new Size(760, this.Height);
            this.Size = new Size(760, this.Height);
        }

        /// <summary>
        /// The <see cref="DMClass"/> whose <see cref="DMRelationship"/>s are being edited by this control
        /// </summary>
        public DMClass Class
        {
            get { return _dmClass; }
            set
            {
                _dmClass = value;
                RelationshipSelector.BusinessObject = value;
                UpdateState();
            }
        }

        public IBOParentChildrenSelector RelationshipSelector
        {
            get { return _relationshipSelector; }
        }

        public IBusinessObjectControl RelationshipEditorControl
        {
            get { return _relationshipEditorControl; }
        }

        private void UpdateState()
        {
            this.Enabled = _dmClass != null;
        }
//        /// <summary>
//        /// The <see cref="DMRelationship"/>s being managed by this control
//        /// </summary>
//        public BusinessObjectCollection<DMRelationship> RelationshipInfos
//        {
//            get { return (BusinessObjectCollection<DMRelationship>) _gridAndBOEditorControl.GridControl.Grid.BusinessObjectCollection; }
//        }
//        /// <summary>
//        /// The <see cref="DMRelationship"/> currently selected in the Grid (i.e. currently being edited)
//        /// </summary>
//        public DMRelationship Relationship
//        {
//            get { return _gridAndBOEditorControl.CurrentBusinessObject; }
//            set { _gridAndBOEditorControl.CurrentBusinessObject = value; }
//        }
//        /// <summary>
//        /// The <see cref="UI.DMRelatedPropertiesControl"/> being used to Manage the 
//        /// currently selected  <see cref="DMRelationship"/>'s
//        /// <see cref="DMRelationshipProperty"/>s
//        /// </summary>
//        public DMRelatedPropertiesControl DMRelatedPropertiesControl
//        {
//            get { return _relatedPropertyInfosControl; }
//        }

        public void SetForm(IFormHabanero form)
        {
            
        }
    }
}
